import common from './common.js'

//参数params，url
class Request {
  
  get(url,method="get",params={}) {
    return new Promise((resolve,reject)=>{
      uni.request({
        url: common.baseUrl + url,
        data: params,
        method: method,
        header: {
          'content-type': 'application/json'
        },
        // 设置请求的 header  
        success:res=>{
          resolve(res.data)
        },
        fail:error=>{
          reject(error)
        }
      })
    })
  }

  post(url,data){
    return this.get(url,"post",data)
  }
}



export default new Request()



// 调用方法

// get
// import request from '../../common/ajax.js';
// async xuanran() {
// 				let res = await request.get('/classic/latest')
// 				console.log(res)
// 				this.result = res
// 			},

// post

// async changeNum() {
// 				this.$emit('childFn', this.result.like_status);
// 				const url = this.like_status ? '/like/cancel' : '/like'
// 				let res = await request.post(url, {
// 					art_id: this.result.id,
// 					type: this.result.type
// 				})
// 				console.log(res);
// 			}
// 		}